using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace sharpTV.Entities
{
    /// <summary>
    /// Controller class for sharpTV_Timelines
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class TimelineController
    {
        // Preload our schema..
        Timeline thisSchemaLoad = new Timeline();
        private string userName = String.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}
					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}
				}
				return userName;
            }
        }
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public TimelineCollection FetchAll()
        {
            TimelineCollection coll = new TimelineCollection();
            Query qry = new Query(Timeline.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public TimelineCollection FetchByID(object TimelineId)
        {
            TimelineCollection coll = new TimelineCollection().Where("TimelineId", TimelineId).Load();
            return coll;
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public TimelineCollection FetchByQuery(Query qry)
        {
            TimelineCollection coll = new TimelineCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object TimelineId)
        {
            return (Timeline.Delete(TimelineId) == 1);
        }
        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object TimelineId)
        {
            return (Timeline.Destroy(TimelineId) == 1);
        }
        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(Guid? TimelineUId,DateTime? DateX,DateTime? StartTime,DateTime? EndTime,short? EventCount,short? SpotCount,DateTime? CreationDate)
	    {
		    Timeline item = new Timeline();
		    
            item.TimelineUId = TimelineUId;
            
            item.DateX = DateX;
            
            item.StartTime = StartTime;
            
            item.EndTime = EndTime;
            
            item.EventCount = EventCount;
            
            item.SpotCount = SpotCount;
            
            item.CreationDate = CreationDate;
            
	    
		    item.Save(UserName);
	    }
    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int TimelineId,Guid? TimelineUId,DateTime? DateX,DateTime? StartTime,DateTime? EndTime,short? EventCount,short? SpotCount,DateTime? CreationDate)
	    {
		    Timeline item = new Timeline();
	        item.MarkOld();
	        item.IsLoaded = true;
		    
			item.TimelineId = TimelineId;
				
			item.TimelineUId = TimelineUId;
				
			item.DateX = DateX;
				
			item.StartTime = StartTime;
				
			item.EndTime = EndTime;
				
			item.EventCount = EventCount;
				
			item.SpotCount = SpotCount;
				
			item.CreationDate = CreationDate;
				
	        item.Save(UserName);
	    }
    }
}
